package concurrency.chapter1;

import java.util.concurrent.TimeUnit;

/**
 * FileName: InterruptDemo
 * Author:   周壮
 * Date:     2020/5/18 7:49
 * Description:
 */
public class InterruptDemo {

    private static int i;
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            while (!Thread.currentThread().isInterrupted()) { //默认情况下 isInterrupted 返回 false、通过 thread.interrupt 变成了 true
                i++;
            }
            System.out.println("Num:" + i);
        }, "interruptDemo");
        thread.start();
        TimeUnit.SECONDS.sleep(1);
        thread.interrupt(); //加和不加的效果

    }
}
